// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
 */

/*\
 * Basic test for the time(2) system call.
 *
 * Verify that time(2) returns the value of time in seconds since the Epoch
 * and stores this value in the memory pointed to by the parameter.
 */

#include <time.h>
#include <errno.h>

#include "tst_test.h"

static time_t tlocal;
static time_t *targs[] = {
	NULL, &tlocal,
};

static void verify_time(unsigned int i)
{
	time_t *tloc = targs[i];
	time_t ret_time = time(tloc);

	if (ret_time == -1) {
		tst_res(TFAIL | TTERRNO, "time()");
		return;
	}

	if (!tloc) {
		tst_res(TPASS, "time() returned value %jd", (intmax_t) ret_time);
	} else if (*tloc == ret_time) {
		tst_res(TPASS,
			"time() returned value %jd, stored value %jd are same",
			(intmax_t) ret_time, (intmax_t) *tloc);
	} else {
		tst_res(TFAIL,
			"time() returned value %jd, stored value %jd are different",
			(intmax_t) ret_time, (intmax_t) *tloc);
	}
}

static struct tst_test test = {
	.test = verify_time,
	.tcnt = ARRAY_SIZE(targs),
};
